home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 071-080 / amok71 / cliutil / callint.mod < prev    next >
Text File  |  1993-11-04  |  4KB  |  111 lines

  1.  
  2. (*  Module  : CallInt
  3.     Author  : Franz Schwarz
  4.     Address : Muehlenstrasse 2
  5.     Address : D-7201 Durchhausen
  6.     Address : Germany
  7.     email   : FIDO: Franz Schwarz, 2:241/7506.18
  8.     email   : uucp: Franz_Schwarz@p18.f7506.n241.z2.fidonet.org
  9.     Date    : 07-May-92
  10.     Language: Oberon
  11.     Compiler: Amiga Oberon V2.14
  12.     Type    : Small CLI utility
  13.     Legal   : Released to the Public Domain
  14.     Required: AmigaOS 2.04 or higher
  15.     Info    : This command just calls the resident INTERNAL command of the
  16.     Info    : the same name as it was invoked with. It provides the ultimate
  17.     Info    : solution for problems that arise from other programs which
  18.     Info    : expect the respective command in the C: directory, although it
  19.     Info    : may have become an internal resident command of Kickstart2.0 or
  20.     Info    : higher. Since this program always calls the internal command
  21.     Info    : in an documented and compliant and compatible way,
  22.     Info    : all compatability problems have gone, as e.g. the old 1.3
  23.     Info    : c:run command which still runs under 2.0 but doesn't propagate
  24.     Info    : the alias list to the child process it invoces etc.
  25.     Info    : Just copy this utility to c: with the respective name
  26.     Info    : (e.g. 'copy CallInt c:Run') multiple times or simply copy it
  27.     Info    : once and make links to it using 'makelink', e.g.:
  28.     Info    : 'Copy CallInt c:, makelink c:run c:callint hard,
  29.     Info    :  makelink c:cd c:run hard' etc. BTW: Workbench start is
  30.     Info    : detected and will result in an immediate return
  31.     Info    :
  32.     Problems: None known
  33.     History : 20-Apr-92 First version, 38.0, always return NULL to the CLI
  34.     History : 21-Apr-92 Version 38.01, added return code classes as a
  35.     History :   work around to the CLI return code problem
  36.     History : 23-Apr-92 Version 38.1, found the OberonLib.Result variable
  37.     History :   CallInt now finally returns the correct CLI return code!
  38.     History :   Initial public release!
  39.     History : 07-May-92 Fixed stack size bug, which was due to inconsitencies
  40.     History :   in DOS structures (Process: size in bytes, CLI: size in longs
  41.     History :   RunCommand: size in bytes)
  42.  *)
  43.  
  44. (* thoroughly tested, thus: *)
  45. (* $OvflChk- $RangeChk- $StackChk- $NilChk- $ReturnChk- $CaseChk- *)
  46.  
  47. (* BTW: You should use SmallCode/SmallData!! *)
  48.  
  49. MODULE CallInt;
  50.  
  51. IMPORT S: SYSTEM, o: OberonLib, e: Exec, d: Dos;
  52.  
  53. CONST namBufSize = 1024;
  54.       version = "\000$VER: CallInternal 38.11 (07-May-92)";
  55.  
  56. VAR rc: LONGINT;
  57.  
  58.  
  59. PROCEDURE main(): LONGINT;
  60.  
  61. VAR cmdseg: d.SegmentPtr;
  62.     rc, n: LONGINT;
  63.     nambuf, cmdnam, argstr: e.STRPTR;
  64.     me : d.ProcessPtr;
  65.   BEGIN
  66.     (* persuade Oberon to keep the version string in the executable *)
  67.     IF S.ADR(version)#NIL THEN END;
  68.     rc := 20;
  69.     IF (d.dos.lib.version >= 37) & ~o.wbStarted THEN
  70.       nambuf := e.AllocVec(namBufSize, e.any);
  71.       IF nambuf#NIL THEN
  72.         IF d.GetProgramName(nambuf^, namBufSize) THEN
  73.           cmdnam := d.FilePart(nambuf^);
  74.           e.Forbid();
  75.           cmdseg:=NIL;
  76.           LOOP
  77.             cmdseg := d.FindSegment(cmdnam^, cmdseg, d.DOSTRUE);
  78.             IF cmdseg = NIL THEN
  79.               EXIT;
  80.             ELSIF cmdseg.uc = d.cmdInternal THEN
  81.               EXIT;
  82.             END;
  83.           END;
  84.           e.Permit();
  85.           IF cmdseg#NIL THEN
  86.             argstr := o.dosCmdBuf;
  87.             me := S.VAL(d.ProcessPtr, o.Me);
  88.             rc := d.RunCommand (cmdseg.seg,ASH(me.cli.defaultStack,2),
  89.                                 argstr^, o.dosCmdLen);
  90.           ELSE
  91.             n:=d.Printf("Can't find INTERNAL %s\n", cmdnam);
  92.             n:=d.SetIoErr (d.objectNotFound);
  93.           END;
  94.         ELSE
  95.           n:=d.WriteStr ("Can't get program name\n"); (* IoErr already set by
  96.                                                     Dos.GetProgramName() *)
  97.         END;
  98.         e.FreeVec(nambuf);
  99.       ELSE
  100.         n:=d.WriteStr ("No memory for command name buffer\n");
  101.         n:=d.SetIoErr (d.noFreeStore);
  102.       END;
  103.     END;
  104.     RETURN rc;
  105.   END main;
  106.  
  107.  
  108. BEGIN
  109.   o.Result:=main();
  110. END CallInt.
  111.